//
//  MCSweepPayResultViewController.swift
//  StoreManage
//
//  Created by MC on 2018/5/18.
//  Copyright © 2018年 MC. All rights reserved.
//

import UIKit

class MCSweepPayResultViewController: MCViewController {

    var dataDict = NSDictionary()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        baseSetting()
        
        initUI()
        
        sendNetworking()
    }
    
    // MARK: - System Delegate
    
    // MARK: - Custom Delegate
    
    // MARK: - Action
    @objc func sureButtonClicked() {
        
        for i in 0..<(self.navigationController?.viewControllers.count)! {
            
            if self.navigationController?.viewControllers[i].isKind(of: MCSweepPayViewController.self) == true {
                
                _ = self.navigationController?.popToViewController(self.navigationController?.viewControllers[i] as! MCSweepPayViewController, animated: true)
                break
            } else {
                self.navigationController?.popViewController(animated: true)
            }
        }
        
        
    }
    
    // MARK: - Network
    func sendNetworking() {
        
        storeNameView.detailLabel.text = dataDict["storeName"] as? String ?? ""
        let totalFee = dataDict["totalFee"] as? NSNumber ?? 0
        
        moneyView.detailLabel.text = MCString_judgemantDecimalsIsZero(figure: totalFee.intValue)

        timeView.detailLabel.text = dataDict["createTime"] as? String ?? ""
        orderView.detailLabel.text = dataDict["result"] as? String ?? ""

        payCodeView.detailLabel.text = dataDict["takeCode"] as? String ?? ""

    }
    
    // MARK: - Method
    func baseSetting() {
        self.title = "扫码收款"
        self.view.backgroundColor = UIColor.MCGray_light
    }
    
    func initUI() {
        view.addSubview(statusButton)
        statusButton.snp.remakeConstraints { (make) ->Void in
            make.centerX.equalTo(view)
            make.top.equalTo(30)
        }
        
        view.addSubview(bgView)
        bgView.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(10)
            make.right.equalTo(-10)
            make.top.equalTo(statusButton.snp.bottom).offset(30)
            make.height.equalTo(36*5 + 50 + 5)
        }
        
        bgView.addSubview(promptView)
        promptView.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(0)
            make.right.equalTo(0)
            make.top.equalTo(0)
            make.height.equalTo(50)
        }
        
        bgView.addSubview(promptView)
        promptView.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(10)
            make.right.equalTo(-10)
            make.top.equalTo(0)
            make.height.equalTo(55)
        }
        
        bgView.addSubview(storeNameView)
        storeNameView.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(10)
            make.right.equalTo(-10)
            make.top.equalTo(promptView.snp.bottom)
            make.height.equalTo(36)
        }
        
        bgView.addSubview(moneyView)
        moneyView.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(10)
            make.right.equalTo(-10)
            make.top.equalTo(storeNameView.snp.bottom)
            make.height.equalTo(36)
        }

        
        bgView.addSubview(timeView)
        timeView.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(10)
            make.right.equalTo(-10)
            make.top.equalTo(moneyView.snp.bottom)
            make.height.equalTo(36)
        }

        
        bgView.addSubview(orderView)
        orderView.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(10)
            make.right.equalTo(-10)
            make.top.equalTo(timeView.snp.bottom)
            make.height.equalTo(36)
        }

        bgView.addSubview(payCodeView)
        payCodeView.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(10)
            make.right.equalTo(-10)
            make.top.equalTo(orderView.snp.bottom)
            make.height.equalTo(36)
        }

        
        view.addSubview(sureButton)
        sureButton.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(20)
            make.right.equalTo(-20)
            make.top.equalTo(bgView.snp.bottom).offset(50)
            make.height.equalTo(36)
        }
    }
    
    // MARK: - Setter & Getter
    
    
    lazy var statusButton: UIButton = {
        let button = UIButton.init(type: UIButtonType.custom)
        button.titleLabel?.font = MCFont(20)
        button.setTitle("  收款成功", for: .normal)
        button.setTitleColor(UIColor.MCWords, for: .normal)
        button.setImage(#imageLiteral(resourceName: "SweepPay_success"), for: .normal)
        return button
    }()
    
    lazy var bgView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.white
        view.layer.masksToBounds = true
        view.layer.cornerRadius = 5
        return view
    }()
    
    lazy var promptView: MCReuse_entryView = {
        let view = MCReuse_entryView()
        view.titleLabel.text = "订单信息"
        view.titleLabel.font = MCFont(18)
        return view
    }()

    
    lazy var storeNameView: MCReuse_entryView = {
        let view = MCReuse_entryView()
        view.titleLabel.text = "门店名称"
        view.lineView.isHidden = true
        return view
    }()
    
    lazy var moneyView: MCReuse_entryView = {
        let view = MCReuse_entryView()
        view.titleLabel.text = "收款金额"
        view.lineView.isHidden = true
        return view
    }()
    
    
    lazy var timeView: MCReuse_entryView = {
        let view = MCReuse_entryView()
        view.titleLabel.text = "操作时间"
        view.lineView.isHidden = true
        view.isShowArrow = false
        return view
    }()
    
    lazy var orderView: MCReuse_entryView = {
        let view = MCReuse_entryView()
        view.titleLabel.text = "交易单号"
        view.lineView.isHidden = true
        return view
    }()
    
    lazy var payCodeView: MCReuse_entryView = {
        let view = MCReuse_entryView()
        view.titleLabel.text = "收货编码"
        view.lineView.isHidden = true
        return view
    }()
    
    lazy var sureButton: UIButton = {
        let button = UIButton.init(type: .custom)
        button.titleLabel?.font = MCFont(14)
        button.backgroundColor = UIColor.MCMain
        button.setTitle("完成", for: .normal)
        button.layer.cornerRadius = 5
        button.layer.masksToBounds = true
        button.setTitleColor(UIColor.white, for: .normal)
        button.addTarget(self, action: #selector(sureButtonClicked), for: .touchUpInside)
        return button
    }()


}




